<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>转圈圈</title>

    <!-- vue -->
    <script src="./assets/js-vue/vue.js"></script>
    <!--element-->
    <link rel="stylesheet" type="text/css" href="./assets/js-vue/element/index.css">
    <!--<link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">-->
    <script src="./assets/js-vue/element/index.js"></script>
    <script type="text/javascript" src="./assets/jquery-3.6.1.min.js"></script>
    <!--公共方法-->
    <script type="text/javascript" src="./utils/common.js"></script>
    <!--请求封装-->
    <script type="text/javascript" src="utils/myAjax.js"></script>

    <style>
        .container{
                width: 300px;
                height: 300px;
                position:fixed ;
                left: 50%;
                top: 50%;
                transform: translateX(-50%) translateY(-50%);
        }

        .box{
            width: 100px;
            height: 100px;
        }

        .red{
            background-color: red;
        }

        .green{
            background-color: green !important;
        }


    </style>


</head>
<body>


    <div id="app">
        <div>  <el-button type="primary" @click=" start()">开始</el-button></div>


            <div class="container" :style="{top:top,left:left}">
                <div style="display: flex; justify-content: space-between">
                    <div :class="{box:true,red:true,green:light == 1}" ></div>
                    <div :class="{box:true,red:true,green:light == 2}" ></div>
                </div>
                <div style="display: flex;justify-content: center">
                    <div class="box red"></div>
                </div>
                <div style="display: flex; justify-content: space-between">
                    <div :class="{box:true,red:true,green:light == 4}"> </div>
                    <div :class="{box:true,red:true,green:light == 3}"></div>
                </div>

            </div>
    </div>


<script type="text/javascript">
    var vm = new Vue({
        el:'#app',
        data(){
            return{
                top:'50%',
                left:'50%',
                light:0,
            }
        },
        created(){
            let rand = this.getRandomNumber(500,600);
            this.top = rand + 'px';
            this.left = rand + 'px';
        },
        methods:{
            start(){
                //转动
                let that = this;
                let interval = setInterval(()=>{
                    if(that.light == 4){
                        that.light = 1
                    }else{
                        that.light ++;
                    }
                }, 200);

            },
            getRandomNumber(min, max) {
                min = Math.ceil(min);
                max = Math.floor(max);
                return Math.floor(Math.random() * (max - min + 1)) + min;
            }
        }
    })

</script>



</body>
</html>